<?php

namespace App\Http\Middleware;

use Closure;
use App\Service\RedisService;

class RedisToken
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $token = $request->header('Authorization');
        $redis = new RedisService();
        $data  = $redis->renewal($token);
        if($data['code'] != 200){
            return ['msg'=>'操作失败 请重新登录','code'=>1002];
        }
        $request->user = $data['data'];
        return $next($request);
    }
}
